import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

const routes = [
  {path: '/404', name: '404', component: () => import(/* webpackChunkName: "parent" */ '@/views/common/404'), meta: {title: '404未找到'}},
  {path: '/login', name: 'login', component: () => import(/* webpackChunkName: "parent" */ '@/views/common/Login'), meta: {title: '登录'}},
  {
    path: '/',
    name: 'index',
    component: () => import('@/views/common/Index'),
    meta: {title: '首页'},
    redirect: {name: 'dashboard'},
    children: [
      // 医务管理
      {path: 'hospital-manage', name: 'hospital-manage', component: () => import('@/views/page/healthcareManagement/HospitalManage.vue'), meta: {title: '院区管理'}},
      {path: 'department-manage', name: 'department-manage', component: () => import('@/views/page/healthcareManagement/DepartmentManage.vue'), meta: {title: '科室管理'}},
      {path: 'doctor-manage', name: 'doctor-manage', component: () => import('@/views/page/healthcareManagement/DoctorManage.vue'), meta: {title: '医生管理'}},
      {path: 'pharmacist-manage', name: 'pharmacist-manage', component: () => import('@/views/page/healthcareManagement/PharmacistManage.vue'), meta: {title: '药师管理'}},
      {path: 'schedule-rule-manage', name: 'schedule-rule-manage', component: () => import('@/views/page/healthcareManagement/ScheduleRuleManage.vue'), meta: {title: '排班规律管理'}},
      {path: 'schedule-manage', name: 'schedule-manage', component: () => import('@/views/page/healthcareManagement/ScheduleManage.vue'), meta: {title: '排班管理'}},
      {path: 'service-type-manage', name: 'service-type-manage', component: () => import('@/views/page/healthcareManagement/ServiceTypeManage.vue'), meta: {title: '服务类型管理'}},
      {path: 'doctor-service-manage', name: 'doctor-service-manage', component: () => import('@/views/page/healthcareManagement/DoctorServiceManage.vue'), meta: {title: '医生服务管理'}},
      // 订单管理
      {path: 'order-appointment', name: 'order-appointment', component: () => import('@/views/page/orderManagement/OrderAppointment.vue'), meta: {title: '预约挂号订单'}},
      {path: 'order-inquiry', name: 'order-inquiry', component: () => import('@/views/page/orderManagement/OrderInquiry.vue'), meta: {title: '问诊订单'}},
      {path: 'order-evaluation', name: 'order-evaluation', component: () => import('@/views/page/orderManagement/OrderEvaluation.vue'), meta: {title: '评价管理'}},
      {path: 'order-ca', name: 'order-ca', component: () => import('@/views/page/orderManagement/OrderCA.vue'), meta: {title: 'CA签章记录'}},
      // 药品管理
      {path: 'pharmacy-manage', name: 'pharmacy-manage', component: () => import('@/views/page/drugManagement/PharmacyManage.vue'), meta: {title: '药房管理'}},
      {path: 'pharmacy-drug-config', name: 'pharmacy-drug-config', component: () => import('@/views/page/drugManagement/PharmacyDrugConfig.vue'), meta: {title: '科室药房配置'}},
      {path: 'drug-manage', name: 'drug-manage', component: () => import('@/views/page/drugManagement/DrugManage.vue'), meta: {title: '药品管理'}},
      // 内容管理
      {path: 'content-carousel', name: 'content-carousel', component: () => import('@/views/page/content/ContentCarousel.vue'), meta: {title: '轮播管理'}},
      {path: 'content-notice', name: 'content-notice', component: () => import('@/views/page/content/ContentNotice.vue'), meta: {title: '公告管理'}},
      {path: 'content-news', name: 'content-news', component: () => import('@/views/page/content/ContentNews.vue'), meta: {title: '资讯管理'}},
      // 患者管理
      {path: 'patient-manage', name: 'patient-manage', component: () => import('@/views/page/patientManagement/PatientManage.vue'), meta: {title: '就诊人管理'}},
      {path: 'first-diagnosis-manage', name: 'first-diagnosis-manage', component: () => import('@/views/page/patientManagement/FirstDiagnosisManage.vue'), meta: {title: '首诊记录管理'}},
      {path: 'inspection-manage', name: 'inspection-manage', component: () => import('@/views/page/patientManagement/InspectionManage.vue'), meta: {title: '检验检查记录管理'}},
      // 首页
      {path: 'dashboard', name: 'dashboard', component: () => import('@/views/common/Dashboard.vue'), meta: {title: '系统首页'}},
    ],
    // 路由导航守卫,用于用户认证
    beforeEnter: (to, from, next) => {
       let loginUser = window.sessionStorage.getItem('loginUser');
       if (loginUser) {
         // 认证成功,允许路由
         next();
       } else {
        // 认证失败,跳转到登录组件
        next({name: 'login'});
      }
    }
  },
  {path: '*', redirect: {name: '404'}}
];

const router =  new VueRouter({
  scrollBehavior: () => ({ x: 0, y: 0 }),
  routes
});

export default router;
